﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Gao.Poker.Domain;
using Gao.Poker.Services;
using Gao.Poker.ViewModel;

namespace Gao.Poker.App.Win
{
    /// <summary>
    /// Interaction logic for CompetitionEndWin.xaml
    /// </summary>
    public partial class CompetitionEndWin : Window
    {
        private CompetitionViewModel _viewModel;
        public CompetitionViewModel ViewModel
        {
            get { return _viewModel; }
            set
            {
                _viewModel = value;
                DataContext = _viewModel;
            }
        }
        public Competition Competition { get; set; }

        public CompetitionEndWin()
        {
            InitializeComponent();
        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            CompetitionEntryService service = new CompetitionEntryService();
            CompetitionService cs = new CompetitionService();
            Competition = cs.GetCompetition(Competition.ID);


            if(Competition.State == 0)
            {
                Competition.State = 1;
                cs.Save(Competition);
            }

            TablesService ts = new TablesService();
            ts.Update(Competition.ID);

            service.Update(Competition,ViewModel.Rankings);
            ViewModel.OnPropertyChanged("Members");
            Close();
        }
    }
}
